package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SuperVipCode;
import com.ruoyi.system.service.ISuperVipCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员码Controller
 * 
 * @author mzh
 * @date 2025-08-15
 */
@RestController
@RequestMapping("/VIP_Code/VIP_Code")
public class SuperVipCodeController extends BaseController
{
    @Autowired
    private ISuperVipCodeService superVipCodeService;

    /**
     * 查询会员码列表
     */
    @PreAuthorize("@ss.hasPermi('VIP_Code:VIP_Code:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperVipCode superVipCode)
    {
        startPage();
        List<SuperVipCode> list = superVipCodeService.selectSuperVipCodeList(superVipCode);
        return getDataTable(list);
    }

    /**
     * 导出会员码列表
     */
    @PreAuthorize("@ss.hasPermi('VIP_Code:VIP_Code:export')")
    @Log(title = "会员码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperVipCode superVipCode)
    {
        List<SuperVipCode> list = superVipCodeService.selectSuperVipCodeList(superVipCode);
        ExcelUtil<SuperVipCode> util = new ExcelUtil<SuperVipCode>(SuperVipCode.class);
        util.exportExcel(response, list, "会员码数据");
    }

    /**
     * 获取会员码详细信息
     */
    @PreAuthorize("@ss.hasPermi('VIP_Code:VIP_Code:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superVipCodeService.selectSuperVipCodeById(id));
    }

    /**
     * 新增会员码
     */
    @PreAuthorize("@ss.hasPermi('VIP_Code:VIP_Code:add')")
    @Log(title = "会员码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperVipCode superVipCode)
    {
        return toAjax(superVipCodeService.insertSuperVipCode(superVipCode));
    }

    /**
     * 修改会员码
     */
    @PreAuthorize("@ss.hasPermi('VIP_Code:VIP_Code:edit')")
    @Log(title = "会员码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperVipCode superVipCode)
    {
        return toAjax(superVipCodeService.updateSuperVipCode(superVipCode));
    }

    /**
     * 删除会员码
     */
    @PreAuthorize("@ss.hasPermi('VIP_Code:VIP_Code:remove')")
    @Log(title = "会员码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superVipCodeService.deleteSuperVipCodeByIds(ids));
    }
}
